package com.twu.biblioteca.di;

import com.google.inject.AbstractModule;
import com.google.inject.name.Names;

import com.twu.biblioteca.dao.BookDao;
import com.twu.biblioteca.dao.MovieDao;
import com.twu.biblioteca.dao.UserDao;
import com.twu.biblioteca.dao.memory.MemoryBookDao;
import com.twu.biblioteca.dao.memory.MemoryMovieDao;
import com.twu.biblioteca.dao.memory.MemoryUserDao;
import com.twu.biblioteca.view.command.BookCheckoutCommand;
import com.twu.biblioteca.view.command.BookListCommand;
import com.twu.biblioteca.view.command.Command;
import com.twu.biblioteca.view.command.LoginCommand;
import com.twu.biblioteca.view.command.MovieCheckoutCommand;
import com.twu.biblioteca.view.command.MovieListCommand;
import com.twu.biblioteca.view.command.QuitCommand;
import com.twu.biblioteca.view.command.ReturnBookCommand;
import com.twu.biblioteca.view.command.ReturnMovieCommand;
import com.twu.biblioteca.view.command.StartUpBookListCommand;
import com.twu.biblioteca.view.command.UserInfoCommand;
import com.twu.biblioteca.view.console.ViewResolver;
import com.twu.biblioteca.view.console.resolver.BookListViewResolver;
import com.twu.biblioteca.view.console.resolver.MenuViewResolver;
import com.twu.biblioteca.view.console.resolver.MessageResolver;
import com.twu.biblioteca.view.console.resolver.MovieListViewResolver;
import com.twu.biblioteca.view.console.resolver.UserInfoViewResolver;

public class BibliotecaModule extends AbstractModule {

  @Override
  protected void configure() {
    daoConfiguration();
    viewResolverConfiguration();
    commandConfiguration();
  }

  private void commandConfiguration() {
    bind(Command.class)
        .annotatedWith(Names.named("login"))
        .to(LoginCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("startup"))
        .to(StartUpBookListCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("bookList"))
        .to(BookListCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("checkoutBook"))
        .to(BookCheckoutCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("returnBook"))
        .to(ReturnBookCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("movieList"))
        .to(MovieListCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("checkoutMovie"))
        .to(MovieCheckoutCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("returnMovie"))
        .to(ReturnMovieCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("userInfo"))
        .to(UserInfoCommand.class);

    bind(Command.class)
        .annotatedWith(Names.named("quit"))
        .to(QuitCommand.class);
  }

  private void daoConfiguration() {
    bind(BookDao.class).to(MemoryBookDao.class);
    bind(MovieDao.class).to(MemoryMovieDao.class);
    bind(UserDao.class).to(MemoryUserDao.class);
  }

  private void viewResolverConfiguration() {
    bind(ViewResolver.class)
        .annotatedWith(Names.named("welcome"))
        .to(MessageResolver.class);

    bind(ViewResolver.class)
        .annotatedWith(Names.named("bookList"))
        .to(BookListViewResolver.class);

    bind(ViewResolver.class)
        .annotatedWith(Names.named("userInfo"))
        .to(UserInfoViewResolver.class);

    bind(ViewResolver.class)
        .annotatedWith(Names.named("movieList"))
        .to(MovieListViewResolver.class);

    bind(ViewResolver.class)
        .annotatedWith(Names.named("menu"))
        .to(MenuViewResolver.class);
  }
}

